Skip to content

refactor(binary): rewrite pre-2018 ref-patterns to match ergonomics - #91

Merged
jhamill34 merged 1 commit into
claude/issue-1-phase2-runnersfrom
claude/issue-1-phase2-binaries
Aug 26, 2026
Merged

refactor(binary): rewrite pre-2018 ref-patterns to match ergonomics#91
jhamill34 merged 1 commit into
claude/issue-1-phase2-runnersfrom
claude/issue-1-phase2-binaries

Conversation

@jhamill34

Copy link
Copy Markdown
Owner

Summary

Closes #85 (Phase 2 of #1). Stacked on #90 (runners/*), which is stacked on #89 (usecases/*), which is stacked on #88 (Phase 1's lint policy).

Same transform as #89/#90, applied to binary/apicli and binary/apid:

  • if let &Some(ref x) = &y { ... }if let Some(x) = &y { ... }
  • match &value { &Variant(ref x) => ..., ... }match value { Variant(x) => ..., ... }

Crates touched: apicli (33 sites across engine.rs, path.rs, stub.rs, template.rs), apid (1 site).

Two sites needed care beyond the mechanical transform:

  • template.rs's Integer(key) arm: the original explicit-deref pattern bound an owned i64 (the payload is Copy); plain ergonomics would have silently changed the binding to &i64 instead. Fixed by dereferencing at the use site so the type stays identical.
  • apid/main.rs's provide_input: matches against a &mut-sourced get_mut() call. Ergonomics binds the tuple's second field as &mut Sender where the original bound &Sender — confirmed inert since Sender::send only needs &self.

Worth flagging for anyone auditing this style of cleanup in the future: 30 of apicli's 33 sites (all of path.rs and stub.rs) were not flagged by clippy::ref_patterns/match_ref_pats/needless_borrowed_reference at all — those lints don't reliably fire on &Some(Variant(_))-shaped match arms mixed with _/ref-bound arms in the same match. They were only caught by cross-checking against the manual site inventory from #1's original scoping research, not from clippy's live output. engine.rs's merge() function also intentionally keeps its match &left/match &right scrutinee un-simplified (only the arm patterns lost their &/ref) since left/right are owned values reused later in the same arms.

Confirmed via a full workspace clippy run: zero ref_patterns/match_ref_pats/needless_borrowed_reference warnings remain anywhere in the repo after this PR — closes out #85 completely.

Test plan

  • cargo build -p apicli -p apid --all-features — clean.
  • cargo clippy -p apicli -p apid --all-features — zero warnings from the three targeted lints.
  • cargo test -p apicli -p apid --all-features — 15 tests, 0 failures (including template::test::test_parse_starts_with_index, which exercises the Integer(key) Copy-type fix).
  • cargo clippy --workspace --all-features — zero ref_patterns/match_ref_pats/needless_borrowed_reference warnings workspace-wide.
  • cargo build --workspace --all-features / cargo test --workspace --all-features — clean, zero failures.
  • cargo fmt --all -- --check — clean.

Generated by Claude Code

Closes #85 (Phase 2 of #1). Converts every &Variant(ref x)-style site in
apicli and apid to plain match-ergonomics form -- purely syntactic, binds
the identical reference type as before, with one exception handled
explicitly:

apicli/template.rs's Integer(key) arm bound key: &i64 via ergonomics
where the original &InputTokens::Integer(key) explicit-deref pattern
bound an owned (Copy) i64 -- fixed by dereferencing at the use site
instead of changing the match arm.

apid/main.rs's provide_input handler matches Some((_, tx)) against a
&mut-sourced get_mut() call; ergonomics binds tx: &mut Sender where the
original ref tx bound &Sender, but Sender::send only needs &self so this
is behaviorally inert.

apicli's path.rs and stub.rs account for most of this PR's sites (30 of
33) and weren't flagged by clippy::ref_patterns/match_ref_pats/
needless_borrowed_reference at all -- those lints don't reliably fire on
every &Some(Variant(_))-shaped match arm mixed with `ref`-bound arms in
the same match. Found instead via the original manual site inventory from
#1's scoping research; worth noting since a future clippy-only search of
this codebase would miss them.

apicli/engine.rs's merge() function keeps its outer `match &left`/
`match &right` (left/right are owned Schema values reused later in the
same arms via `one_of.push(left)`/`vec![left, right]`, so the scrutinee
itself can't drop its `&` without moving out from under later use) --
only the arm patterns lost their redundant `&`/`ref`.

apicli/template.rs also fixes the impl ToString for PathKey match's
ref-pattern shape only, not the ToString/Display issue itself (#13).

Confirmed via a full `cargo clippy --workspace --all-features`: zero
ref_patterns/match_ref_pats/needless_borrowed_reference warnings remain
anywhere in the workspace, closing out issue #85.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VzKriyNnMHmqQ6UxPhsv2
@jhamill34
jhamill34 force-pushed the claude/issue-1-phase2-binaries branch from 46ee4e0 to 99cd11d Compare August 26, 2026 23:50
@jhamill34
jhamill34 merged commit 411dea2 into main Aug 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 2 of #1: rewrite ~86 pre-2018 ref-pattern sites to match ergonomics

2 participants